import { getToken } from "./cookies";

// 通过环境获取cookieKey
export function cookieKeys() {
  return {
    tokenKey: process.env.VUE_APP_TOKENKEY,
    userKey: process.env.VUE_APP_USERKEY,
    spaceId: process.env.VUE_APP_SPACEID,
    domain: process.env.VUE_APP_DOMAIN
  };
}

export function initProjectInfo() {
  let token = getToken(cookieKeys().tokenKey);
  let member = getToken(cookieKeys().userKey);
  let spaceId = getToken(cookieKeys().spaceId);

  return new Promise((resolve) => {
    if (token && member && spaceId) {
      try {
        let data = {
          token: {
            token: token
          },
          member: JSON.parse(member),
          spaceId: spaceId
        };
        resolve(data);
      } catch (e) {
        console.log(e);
      }
    }
  });
}
